#include<iostream>
#include<cstring>
#include<deque>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
int n, p, k;
const int N = 1e3 + 10;
vector<PII>edges[N];
int dist[N];
bool st[N];
bool check(int x)
{
	memset(dist, 0x3f, sizeof dist);
	memset(st, 0, sizeof st);
	deque<int> q;
	q.push_back(1);
	dist[1] = 0;
	while (q.size())
	{
		int a = q.front(); q.pop_front();
		if (st[a]) continue;
		st[a] = true;
		for (auto t : edges[a])
		{
			int b = t.first, c = t.second > x ? 1 : 0;
			if (dist[a] + c < dist[b])
			{
				dist[b] = dist[a] + c;
				if (c) q.push_back(b); 
				else q.push_front(b);
			}
		}
	}
	return dist[n] <= k;
}
int main()
{
	cin >> n >> p >> k;
	for (int i = 1; i <= p; i++)
	{
		int a, b, c; cin >> a >> b >> c;
		edges[a].push_back({ b,c });
		edges[b].push_back({ a,c });
	}
	int l = 0, r = 1e6;
	while (l < r)
	{
		int mid = (l + r) / 2;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	if (dist[n] == 0x3f3f3f3f) cout << -1 << endl;
	else cout << l << endl;
	return 0;
}





